package Lamport;

import java.io.*;
import java.net.*;
import java.io.IOException;

public class LamportClient extends Thread{

	private String hostName;

	public LamportClient(String hostName){
		this.hostName = hostName;
	}

	Socket echoSocket = null;
	PrintWriter out = null;
	BufferedReader in = null;

	FileInputStream fis = null;
	BufferedInputStream bis = null;
	DataInputStream dis = null;

	Thread T;

	Runnable clientRunnable = new Runnable(){

		@SuppressWarnings("unused")
		public void run(){
			try {

				GUI.incrementTimer(1);

				InetAddress localaddr = InetAddress.getLocalHost();
				System.out.println ("Local IP Address : " + localaddr );
				System.out.println ("Local hostname   : " + localaddr.getHostName());
				System.out.println ("Timer: " + GUI.lamportTimer);

				echoSocket = new Socket(hostName, 7);
				System.out.println("Remote Hostname Address: " + echoSocket.getInetAddress());
				out = new PrintWriter(echoSocket.getOutputStream(), true);
				in = new BufferedReader(new InputStreamReader(
						echoSocket.getInputStream()));
				System.out.println(echoSocket.getOutputStream());
			} catch (UnknownHostException e) {
				System.err.println("Don't know about host");
				System.exit(1);
			} catch (IOException e) {
				System.err.println("Couldn't get I/O for "
						+ "the connection.");
				System.exit(1);
			}
			BufferedReader stdIn = new BufferedReader(
					new InputStreamReader(System.in));
			String userInput;
			
			out.flush();
			try {
				in.readLine();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}


			try {
				while ((userInput = stdIn.readLine()) != null) {

				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			out.close();
			try {
				in.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				stdIn.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				echoSocket.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}


	};

}


